import Controller from 'castle-koa/dist/lib/controller'
//文章
/**,
   //文章ID ARID BIGINT ,
   //NavID NAID BIGINT ,
   //用户ID UID BIGINT ,
   //文章标题 Tile CHAR(250) ,
   //简略标题 SimpleTile CHAR(250) ,
   //关键字 KeyWords CHAR(250) ,
   //内容摘要 Abstract TEXT ,
   //发布时间 CTime TIMESTAMP ,
   //文章来源 Source CHAR(50) ,
   //发布状态 PubishedStatus TINYINT(1) ,
   //审核状态 ExamineStatus TINYINT(1) ,
   */
export default class Artical extends Controller{
    /**
     * 新建文章
     */
    async addArtical(post){
        /**
         * 如果一表成功，执行二表，
         * 二表失败，删除一表
         */
        const add = await this.M("Artical").add({Tile:post.Tile,SimpleTile:post.SimpleTile,KeyWords:post.KeyWords,Abstract:post.Abstract,Source:post.Source,UID:post.UID});
        if(add!=null){
            const add2 = await this.M("ArticalContent").add({ARID:add.ARID,Conntent:post.Content})
            console.log(add2)
            if(add2!=null){
                return {
                    status:true,
                    message:"新建成功..."
                }
            }
            await this.M("Artical").where({ARID:add.ARID}).del();
            return {
                status:false,
                message:"添加失败..."
            }
           
        }
        return {
            status:false,
            message:"添加失败..."
        }
    }
/**
 * 如果审核成功，改变ExamineStatus
 */
    async addadopt(post){
        this.M("Artical").where({ARID:4}).save({ExamineStatus:1})

        //this.M("Nav").where({NAID:post.NAID}).save({Tile:post.Tile,UID:post.user.UID});
    }
}
